package com.invite.me.beans.adpater;

import android.util.Log;


import com.google.gson.Gson;
import com.invite.me.api.UrlConstants;
import com.invite.me.beans.fabean.InformationmzleFa;
import com.invite.me.beans.res.InformationmyzlBean;
import com.invite.me.ui.cehualan.fragment.InFormationYaoyueFragment;
import com.invite.me.util.SspPrefUtils;
import com.invite.me.wlqq.Constants;
import com.invite.me.wlqq.Contract;
import com.invite.me.wlqq.RxJavaDataImpl;

import java.io.IOException;
import java.util.HashMap;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

public class InformationPresenter implements Contract.BasePresenter{
    InFormationYaoyueFragment splashActivity;

    public InformationPresenter(InFormationYaoyueFragment signInActivity) {
        this.splashActivity = signInActivity;
        splashActivity.setPresenter(this);
    }

    @Override
    public void start() {

    }


    //我的邀约列表
    public void tijiaoshimingrenzheng(String intention, String keyword, int offset, int page, String sort){

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put(Constants.HEADER_KEY, Constants.HEADER_VALUE);
        hashMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));
        InformationmzleFa logeInDataBean = new InformationmzleFa();
        logeInDataBean.setCategory("1");

//        logeInDataBean.setIntention(intention);
//        logeInDataBean.setKeyword(keyword);
//        logeInDataBean.setOffset(offset);
//        logeInDataBean.setPage(page);
//        logeInDataBean.setSort(sort);
        Gson gson = new Gson();
        String phoneNumber = gson.toJson(logeInDataBean);
        RequestBody requestBody = RxJavaDataImpl.getRequestBody(phoneNumber);
        RxJavaDataImpl.postData(UrlConstants.API_YYLB, hashMap, requestBody,new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();
                        InformationmyzlBean gankInfo = gson.fromJson(str, InformationmyzlBean.class);
                        splashActivity.onDataSucess(gankInfo);


                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.e("onerror", e+"" );
                splashActivity.onDataFaile(e);
            }

            @Override
            public void onComplete() {
                splashActivity.onComplete();
            }
        });
    }

}
